#include "../lib/inc/stm32f10x_conf.h"
#include "tim_irq.h"
#include <stdio.h>


static TIM_FUN tim_funs[5] = {NULL};

void SetTimIrqFun(IRQ_TIM_E tim, TIM_FUN fun) {
    tim_funs[tim] = fun;
}

extern "C" {

void TIM2_IRQHandler(void) {
	if(TIM2->SR&0x0001) {
        if (tim_funs[TIM2_IRQ] != NULL)
		    tim_funs[TIM2_IRQ]();
	}
	TIM2->SR &= ~(1 << 0);
}

void TIM3_IRQHandler(void) {
	if(TIM3->SR&0x0001) {
        if (tim_funs[TIM3_IRQ] != NULL)
		    tim_funs[TIM3_IRQ]();
	}
	TIM3->SR &= ~(1 << 0);
}

void TIM4_IRQHandler(void) {
	if(TIM4->SR&0x0001) {
		if (tim_funs[TIM4_IRQ] != NULL)
		    tim_funs[TIM4_IRQ]();
	}
	TIM4->SR &= ~(1 << 0);
}

void TIM5_IRQHandler(void) {
	if(TIM5->SR&0x0001) {
		if (tim_funs[TIM5_IRQ] != NULL)
		    tim_funs[TIM5_IRQ]();
	}
	TIM5->SR &= ~(1 << 0);
}

}